#include <stdlib.h>
#include <stdio.h>
#include <pcre.h>

/* gcc -I/usr/local/include -L/usr/local/lib -lpcre pcre.c */

int main (void)
{
    pcre *re;
    const char *error;
    int erroffset;
    int rc;
    int ovector[30];
    int i;
    re = pcre_compile(
	"^A(.*Z)",          /* the pattern */
	PCRE_UTF8,        /* use UTF-8 option  */
	&error,           /* for error message */
	&erroffset,       /* for error offset */
	NULL);            /* use default character tables */
    rc = pcre_exec(
	re,             /* result of pcre_compile() */
	NULL,           /* we didn't study the pattern */
	"ABCDXZ",  /* the subject string */
	6,             /* the length of the subject string */
	0,              /* start at offset 0 in the subject */
	0,              /* default options */
	ovector,        /* vector of integers for substring information */
	30);            /* number of elements (NOT size in bytes) */
    if (!rc) {
	printf ("Not matched!!\n");
	return 0;
    }
    printf ("Matched!!\n");
    printf ("How many captures? %d\n",rc - 1);
    for (i = 2; i < (rc * 2); i+=2) {
	printf ("Substring (%d,%d)\n", ovector[i], ovector[i+1]);
    }
    return 0;
}


